function sortArray(arr) {
    let tempArr = []
    for (let i = 0; i < arr.length; i++) {

        const element = new Number(arr[i]);
        tempArr.push(element);
    }
    console.log(tempArr);
    return arr.sort((a, b) => {
        // parseInt(a) - parseInt(b);
        return parseInt(b) - parseInt(a);
    });
}

// let arr = ["2.1.0", "1.5", "2", "1.1.999.1.2.3", "0.10.0"];

let arr = ["1.01",
    "1.001"
];
// console.log(sortArray(arr));

/**
 * 分割字符串，加0法
 * @param {String} v1 
 * @param {String} v2 
 */
let compareVersion = function(v1, v2) {
    let arr1 = v1.split('.');
    let arr2 = v2.split('.');

    //遍历较长的数组进行比较
    let len = Math.max(arr1.length, arr2.length);
    for (let i = 0; i < len; i++) {
        //如果有数的话，就赋值，否则默认0
        const cur = arr1[i] || 0;
        const next = arr2[i] || 0;
        //比较
        if (arr1[i] === arr2[i]) continue;
        if (parseInt(cur) > parseInt(next)) {
            return 1;
        } else if (parseInt(cur) < parseInt(next)) {
            return -1;
        }
    }
    return 0;
}
let res = arr.sort(compareVersion);
// console.log(res);
console.log(compareVersion("1.0.1",
    "1"));
//